package com.tjetc.service.impl;

import com.tjetc.common.JsonResult;
import com.tjetc.dao.LikesMapper;
import com.tjetc.service.LikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LikesServiceImpl implements LikesService {

    @Autowired
    private LikesMapper likesMapper;

    // 添加点赞 - 景点
    @Override
    public JsonResult addlikespot(Long userId, Long spotId) {
        int result = likesMapper.insertSpot(userId, spotId);
        return result > 0 ? JsonResult.success("点赞成功") : JsonResult.fail("点赞失败，可能已存在");
    }

    // 取消点赞 - 景点（根据 bookmark_id 删除）
    @Override
    public JsonResult cancellikesspot(Long bookmarkId) {
        int result = likesMapper.deleteSpot(bookmarkId);
        return result > 0 ? JsonResult.success("取消点赞成功") : JsonResult.fail("取消点赞失败，记录不存在");
    }

    // 添加点赞 - 区域
    @Override
    public JsonResult addlikeregion(Long userId, Long regionId) {
        int result = likesMapper.insertRegion(userId, regionId);
        return result > 0 ? JsonResult.success("区域点赞成功") : JsonResult.fail("区域点赞失败，可能已存在");
    }

    // 取消点赞 - 区域
    @Override
    public JsonResult cancellikeregion(Long bookmarkId) {
        int result = likesMapper.deleteRegion(bookmarkId);
        return result > 0 ? JsonResult.success("取消区域点赞成功") : JsonResult.fail("取消区域点赞失败，记录不存在");
    }

    // 添加点赞 - 游记
    @Override
    public JsonResult addliketravelogue(Long userId, Long travelogueId) {
        int result = likesMapper.insertTravelogue(userId, travelogueId);
        return result > 0 ? JsonResult.success("游记点赞成功") : JsonResult.fail("游记点赞失败，可能已存在");
    }

    // 取消点赞 - 游记
    @Override
    public JsonResult cancelliketravelogue(Long bookmarkId) {
        int result = likesMapper.deleteTravelogue(bookmarkId);
        return result > 0 ? JsonResult.success("取消游记点赞成功") : JsonResult.fail("取消游记点赞失败，记录不存在");
    }

    // 添加点赞 - 攻略
    @Override
    public JsonResult addlikeguide(Long userId, Long guideId) {
        int result = likesMapper.insertGuide(userId, guideId);
        return result > 0 ? JsonResult.success("攻略点赞成功") : JsonResult.fail("攻略点赞失败，可能已存在");
    }

    // 取消点赞 - 攻略
    @Override
    public JsonResult cancellikeguide(Long bookmarkId) {
        int result = likesMapper.deleteGuide(bookmarkId);
        return result > 0 ? JsonResult.success("取消攻略点赞成功") : JsonResult.fail("取消攻略点赞失败，记录不存在");
    }

    @Override
    public JsonResult islike(Long userId, Long spotId, Long type) {
        int r;
        if (type == 3L) {
            r = likesMapper.findCityLike(userId, spotId);
        } else if (type == 4L) {
            r = likesMapper.findSpotLike(userId, spotId);
        } else if (type == 5L) {
            r = likesMapper.findyoujiLike(userId, spotId);
        } else if (type == 6L) {
            r = likesMapper.findGuideLike(userId, spotId);
        } else {
            r = 0;
        }



        return JsonResult.success(r);
    }
}
